import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import axios from "axios";
Vue.use(ElementUI)
Vue.config.productionTip = false

import store  from './store'
Vue.prototype.$store = store;
//添加响应拦截器，401错误注销并跳到登录页面
axios.interceptors.response.use(response=>{
  let data = response.data;
  if(data.code==401){
    //显示错误信息
    Vue.prototype.$message.error(data.msg);
    //注销清除登录数据
    store.commit('logout');
    //跳转到登录页面
    router.push({path:'/login'});
    //不需要响应了
    return;
  }
  return response;
})
Vue.prototype.$axios = axios
new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')
